package com.tencent.controller;

import com.tencent.entity.Checkitem;
import com.tencent.entity.Report;
import com.tencent.entity.Result;
import com.tencent.mapper.ReportMapper;
import com.tencent.service.LoginService;
import com.tencent.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 体检报告管理
 */

@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    ReportService reportService;
//    @Autowired
//    private ReportMapper reportMapper;

    @Autowired
    private LoginService loginService;


    @GetMapping
    public Result findReport() {

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String username = (String) authentication.getPrincipal();
//        System.out.println(username);
        Integer id = loginService.findIdByUsername(username);
//        System.out.println("id = " + id);
    // 通过id查询
        List<Checkitem> reports = reportService.findReport(id);
//        reports.forEach(checkitem -> System.out.println(checkitem));

//        List<Checkitem> report = reportService.findReport(82);
//        return Result.success(report);

     return Result.success(reports);
    }

}
